package com.knav.inject;

import android.content.Context;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class InjectImp implements Inject  {
    private Class<? extends InjectImp> tempImp = this.getClass();


    public static Context InjectContext ;
    public static InjectImp builder(Context context){
         InjectContext = context;
        return new InjectImp();
    }

    /**
     * 设置需要驱动注解的类。
     * @param imp
     */
    public void registerConstant(Class<? extends InjectImp> imp){
        this.tempImp = imp;
        // 分发注解
        dispatchInject();

    }

    private void dispatchInject() {
        // 获取子类
        Class<? extends InjectImp> subClass = this.tempImp.asSubclass(InjectImp.class);
        Dispatcher dispatcher = new Dispatcher();
        Field[] fields = subClass.getFields();
        Method[] methods = subClass.getMethods();
        dispatcher.dispatcher(subClass ,fields , methods);
    }
}
